package com.ymatou.iapi.withdraw.testcase;

import java.math.BigDecimal;
import java.util.List;

import net.sf.json.JSONObject;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.withdraw.parameter.HunterQueryListBean;
import com.ymatou.iapi.withdraw.parameter.applyBankWithDrawForHunterBean;
import com.ymatou.iapi.withdraw.service.HunterQueryListCall;
import com.ymatou.iapi.withdraw.service.applyBankWithDrawForHunterCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.database.model.withdraw.Ymt_InvoiceFundFlowLogExample;
import com.ymttest.database.model.withdraw.Ymt_InvoiceOperationLogExample;
import com.ymttest.database.model.withdraw.Ymt_InvoiceSerialSeedExample;
import com.ymttest.database.model.withdraw.Ymt_WithDrawIdempotentExample;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoice;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoiceExample;
import com.ymttest.database.model.withdraw.Ymt_WithDrawInvoiceXloboLogExample;
import com.ymttest.database.sqlwapper.WithdrawWapper;
import com.ymttest.utils.TestDataManager;
/**
*提现记录列表--推手提现记录查询
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_HunterQueryList{
	private static HunterQueryListBean bean;
	private static HunterQueryListCall call;
	Ymt_WithDrawInvoiceExample ymtinvoive=new Ymt_WithDrawInvoiceExample();//提现申请信息主表
	Ymt_InvoiceSerialSeedExample ymtserialseed=new Ymt_InvoiceSerialSeedExample();//单据编号种子表
	Ymt_WithDrawInvoiceXloboLogExample ymtxlobolog=new Ymt_WithDrawInvoiceXloboLogExample();//提现到贝海的日志
	Ymt_InvoiceFundFlowLogExample ymtflowlog=new Ymt_InvoiceFundFlowLogExample();//资金流转操作日志表
	Ymt_InvoiceOperationLogExample ymtoperationlog=new Ymt_InvoiceOperationLogExample();//单据操作日志表
	Ymt_WithDrawIdempotentExample ymtidempotent=new Ymt_WithDrawIdempotentExample();//提现申请幂等键记录表
	
	applyBankWithDrawForHunterBean bean2=new applyBankWithDrawForHunterBean();
	applyBankWithDrawForHunterCall call2=new applyBankWithDrawForHunterCall();
	
	WithdrawWapper WithdrawWapper=new WithdrawWapper();
	
	private final int sellerid=3383;
	private final String sellerName="wesper";
	
	private final int userId=1234; //分销推手Id hunterId  推手没有余额账户，有服务费帐号和佣金帐号
	private final String userName="maggie8315";//推手Name

	private final String fundAccountId="925CF663-FCBA-4380-846B-32162E58C318";
	private final String fundAccountName="吴文推手";
	private final String fundAccountNo="147258369789";
	
	private final String abroadFundAccountId="a0d8378e-af28-45bc-b211-5304d4869710";
	private final String abroadFundAccountName="wuwen";
	private final String abroadFundAccountNo="123147852963";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("提现记录列表--推手提现记录查询");
	}

	@Before
	public void caseUp() {
		bean=new HunterQueryListBean();
		call=new HunterQueryListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	 private void setHunter() throws Exception {
		 applyBankWithDrawForHunterBean bean=new applyBankWithDrawForHunterBean();
		 applyBankWithDrawForHunterCall call=new applyBankWithDrawForHunterCall();
		//给帐号充值
			String accountid = AccountCallServiceV2.getAccountId(userId, 31);
			AccountCallServiceV2.resetAccount(accountid, new BigDecimal(999999999),
					new BigDecimal(0));
			 
			bean.setUserId(userId);
			bean.setWithDrawChannel(10);
			bean.setAccountTypeId(31);//提现帐户类型Id 31.全球优选-推手销售佣金账户 32.全球优选-管理服务费账户（金牌服务商） 33.全球优选-管理服务费账户（普通服务商）
		    bean.setWithDrawAmount(new BigDecimal(1000));
	        bean.setRemark("测试提现到国内银行卡");
	        bean.setApplyUserId(userId);
	        bean.setApplyLoginId(userName);
	         
	        bean.setBankAccountName(fundAccountName);
	        bean.setBankAccountNo(fundAccountNo);
	        bean.setFundAccountId(fundAccountId);
		    bean.setCurrencyType(1);//1 人名币
            bean.setIdempotentNo(new TestDataManager().getRandomNum(8));
         
			call.setData(bean);
			call.callService();		

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_HunterQueryList_001() {
		Logger.start(true,"正例-提现记录列表--推手提现记录查询");
		try {
			//setHunter();
			bean.setUserId(userId);
			call.setData(bean);
			call.callService();	
			
			List<Ymt_WithDrawInvoice> invoivelist = WithdrawWapper.getWithDrawInvoiceByHunter(bean.getUserId());
			Logger.verifyEquals(call.getTotal(), invoivelist.size(), "验证申请总条数");
		     call.getWithDrawInvoiceList().stream().forEach(a->{
		    	 
		    	String  Id= JSONObject.fromObject(a).get("WithDrawInvoiceId").toString();
		    	
				Logger.verifyEquals(true, invoivelist.stream().filter(b->b.getWithDrawInvoiceId().equals(Id)).count()==1, "验证WithDrawInvoiceId");
				
			});
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}